package com.saas.servlet;

import com.saas.entity.Student;
import com.saas.service.IStudentService;
import com.saas.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = "/delete")
public class DeleteStudentServlet extends HttpServlet {

    private IStudentService iss = new StudentServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html");
        resp.setCharacterEncoding("UTF-8");
        req.setCharacterEncoding("UTF-8");

        PrintWriter out = resp.getWriter();

        String id = req.getParameter("id");

        if (iss.deleteStudentById(Integer.parseInt(id))) {
            System.out.println("删除成功");
            out.print("<script>alert('删除成功');location.href='/stus'</script>");
        } else {
            System.out.println("删除失败");
            out.print("<script>alert('删除失败');location.href='/stus'</script>");
        }




    }
}
